// 开启子进程单独运行 爬虫
const pt = require('puppeteer');

; (async () => {

    const bs = await pt.launch(),
        url = 'https://msiwei.ke.qq.com/#category=-1&tab=0',
        pg = await bs.newPage(); // 打开一个浏览器

    await pg.goto(url, {
        timeout: 30 * 1000,
        waitUntil: 'networkidle2'
    });

    const result = await pg.evaluate(() => {
        // 页面中
        // 页面中存在jQuery
        const $ = window.$,
            $item = $('.agency-big-banner-ul .agency-big-banner-li');

        let data = [];

        $item.each((index, item) => {
            const $el = $(item),
                $elLink = $el.find('.js-banner-btnqq');

            const dataItem = {
                cid: $elLink.attr('data-id'),
                href: $elLink.prop('href'),
                imgUrl: $elLink.find('img').prop('src'),
                title: $elLink.prop('title')
            };

            data.push(dataItem);
        });

        return data;
    })
 
    // 关闭浏览器
    await bs.close();

    // 进程发送消息
    process.send(result);

    setTimeout(() => {
        // 进程关闭
        process.exit(0);
    })
})();